import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

public class SampleAndHoldOutputNode extends DrawObject
{
	// DrawObject abilities:
	@Override
	public boolean CanBeDeletedByUser()
	{
		return false;
	};

	@Override
	public boolean CanBeExcitedByUser()
	{
		return true;
	}

	@Override
	public boolean CanBeMovedByUser()
	{
		return false;
	}

	@Override
	public boolean CanBeSelectedByUser()
	{
		return false;
	}
	// end of DrawObject abilities
	
	public SampleAndHoldOutputNode(Point Pos)
	{
		SetPosNoAlignOnGrid(Pos);
		SetSize(new Point(10, 10));
		InitializeExcitement(ExcitementOnceMilliseconds);
	};

	@Override
	protected void AddExcitementForNextTick(double ExcitementAdd)
	{
		// uses the ExciteAsPartner() excitement donation scheme!
	};

	@Override
	protected void AfterCollectingAllExcitementForNextTick()
	{
		// uses the ExciteAsPartner() excitement donation scheme!
	};

	@Override
	public void Draw(Graphics g)
	{
		if (!(IsWithinWindowBounds(this, 0)))
			return;

		// background (overdraw grid)
		if (IsHighlighted || IsPartOfMultiSelection)
			SetColor(g, Color.GREEN);
		else
			SetColor(g, Color.LIGHT_GRAY);
		FillRect(g, Pos.x, Pos.y, Size.x, Size.y);

		// frame
		SetColor(g, GetExcitementColor());
		DrawRect(g, Pos.x, Pos.y, Size.x, Size.y);
	}

	protected void ExciteAsPartner(double ExcitementCurrentNew, DrawObject Sender)
	{
		ExcitementCurrent = ExcitementCurrentNew; // ASSIGN with "=", do NOT add with "+="!
	}

	@Override
	protected void LoseExcitementAndAddExcitementForNextTick()
	{
		// validity: the excitement shortly gets a spike...
		ExcitementCurrent += ExcitementAddForNextTick;

		ShiftExcitementHistory(ExcitementCurrent);

		// validity: ...and then "collapses" again to basic level
		ExcitementCurrent -= ExcitementLossPerTick;

		// verify and reset
		ExcitementCurrent = LimitExcitement(ExcitementCurrent);
		ExcitementAddForNextTick = 0.0; // reset for next usage
	}

	@Override
	public void Move(Point MoveAmount)
	{
		SetPosNoAlignOnGrid(new Point(Pos.x + MoveAmount.x, Pos.y + MoveAmount.y));
	}
}
